#include "test.h"
#include "pw_import_store.h"
#include <fstream>
#include <iostream>
#include <vector>
#include "MD5.h"
#include "hash_table.h"
using namespace std;
long long char_to_ll(char * str){
    long long  k = 0;
    for(int i = 0;str[i] != '\0';i++){
        k = k*10 + str[i];
    }
    return k;
}
bool txt_to_dat(const char* txtpath,const char* datpath,int size){
    fstream Read(txtpath,ios::in);
    fstream Write(datpath,ios::out|ios::binary);
    if(!Read || !Write)return false;
    ID_PASSWORD temp;
    while (size--) {
        Read>>temp.key;
        Read>>temp.value;
        Write.write((char *)&temp,sizeof(ID_PASSWORD));
    }
    Read.close();
    Write.close();
    return true;
}
bool dat_to_txt(const char* datpath,const char* txtpath){
    fstream Read(datpath,ios::in|ios::binary);
    fstream Write(txtpath,ios::out);
    if(!Read || !Write)return false;
    ID_PASSWORD temp;
    Read.seekg(0,ios::end);
    auto end = Read.tellg();
    Read.seekg(0,ios::beg);
    auto size = end / sizeof(ID_PASSWORD) ;
    while (size--) {
        Read.read((char*)&temp.key,sizeof(ID_PASSWORD));
        Write<<temp.key<<" "<<temp.value<<endl;
    }
    Read.close();
    Write.close();
    return true;
}
 vector<pair<int,int>> id_password_to_key_value(vector<pair<string,string>>s){
    vector<pair<int,int>>ans;
    int key,value;
    for(auto x : s)
        key = get_hash(x.first),
        value = get_hash(getMD5(x.second)),
        ans.push_back({key,value});
    return ans;
}
 int key_value_to_txt(vector<pair<int,int>> s, const char* txtpath){
    fstream Write(txtpath,ios::out);
    int size = 0;
    for(auto x : s)
        Write<<x.first<<" "<<x.second<<endl,size++;
    Write.close();
}

